<?php

namespace App\model;

use Illuminate\Database\Eloquent\Model;
use App\Workshop;
use App\Building;
use App\Land;

/**
 * App\model\BrokerRecords
 *
 * @property int $id
 * @property int|null $user_id 用户id
 * @property string|null $type 浏览类的:0厂房1土地2写字楼
 * @property string|null $produce_id 产品id，即土地厂房写字楼的id
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read mixed $types
 * @property-read mixed $url
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\BrokerRecords whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\BrokerRecords whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\BrokerRecords whereProduceId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\BrokerRecords whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\BrokerRecords whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\BrokerRecords whereUserId($value)
 * @mixin \Eloquent
 * @property string|null $user_name 用户名称
 * @property string|null $title 标题
 * @property string|null $logo 首图
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\BrokerRecords whereLogo($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\BrokerRecords whereTitle($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\model\BrokerRecords whereUserName($value)
 */
class BrokerRecords extends Model
{
    //
    protected $table="browse_records";
    protected $appends=['types','url'];

    public function getTypesAttribute(){
        $id =$this->attributes['produce_id'];
        $type =$this->attributes['type'];
        if($type == 0){
            $is_sale = Workshop::find($id)->type;
            if($is_sale ==1){
                return '厂房出售';
            }else{
                return '厂房出租';
            }
        }else if($type == 1){
            $is_sal = Land::find($id)->property;
            if($is_sal ==1){
                return '土地出售';
            }else{
                return '土地出租';
            }
        }else if($type ==2){
            return '写字楼出租';
        }
    }

    public function getUrlAttribute()
    {
        $id =$this->attributes['produce_id'];
        $type =$this->attributes['type'];
        if($type == 0){
            return config('admin.app_outurl').'/detail/'.$id;
        }else if($type == 1){
            return config('admin.app_outurl').'/landDetail/'.$id;
        }else if($type ==2){
            return config('admin.app_outurl').'/buildDetail/'.$id;
        }
    }
}
